package test4_14.demo01;

import java.util.Random;

public class Homework22_5 extends Thread {

    static Random random = new Random();
    private String filename;

    public Homework22_5(String filename) {
        this.filename = filename;
    }

    public void run() {
        try{
            for (int i = 0; i <= 100; i++) {
                System.out.println(filename + "已下载：" + i + "%");
                Thread.sleep(random.nextInt(200)+100);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}


class main {
    public static void main(String[] args) throws InterruptedException {

        System.out.println("下载开始");

        Homework22_5 file1 = new Homework22_5("book1");
        Homework22_5 file2 = new Homework22_5("book2");
        Homework22_5 file3 = new Homework22_5("book3");

        file1.start();
        file2.start();
        file3.start();

        file1.join();
        file2.join();
        file3.join();

        System.out.println("下载结束");
    }
}